const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderData: "",
    orderId: 0,
    showcountDown: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      orderId: options.id
    })
    wx.request({
      url: app.buildUrl('/order/getgroup-info'),
      header: app.buildHeader(),
      data: {
        order_id: options.id
      },
      success(res) {
        if (res.data.code == 200) {
          let data = res.data.data;
          if (data.time_type == 1) {
            let time = data.re_time;
            let d = parseInt(time / 60 / 60 / 24);
            let h = parseInt(time / 60 / 60 % 24);
            let m = parseInt(time / 60 % 60);
            let s = parseInt(time % 60);
            data.re_time = d >= 1 ? `拼团用时 ${d}天${h}时${m}分${s}秒` : `拼团用时 ${h}时${m}分${s}秒`
          } else if (data.time_type == 0) {
            app.countDown({
              date: data.re_time * 1000,
              fun: (options) => {
                that.setData({
                  showcountDown: options.d >= 1 ? `剩余时间 ${options.d}天  ${options.h} : ${options.m} : ${options.s}` : `剩余时间 ${options.h} : ${options.m} : ${options.s}`
                })
              },
              endFun: () => {
                that.setData({
                  showcountDown: "活动已结束"
                })
              }
            })
          }
          that.setData({
            orderData: data
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let that = this;
    if (res.from === 'button') {
      return {
        title: that.data.orderData.active_name,
        path: '/pages/detail/detail?id=' + that.data.orderData.aid,
        imageUrl: that.data.orderData.goods_img
      }
    }
  }
})